package com.example.naodian.controller;



import com.example.naodian.domain.po.EegDataBlock;
import com.example.naodian.domain.vo.EegDataBlockVO;
import com.example.naodian.result.Result;
import com.example.naodian.service.IEegDataBlockService;
import com.example.naodian.service.impl.EegDataReceivingService;
import com.example.naodian.service.impl.EegDataSaveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>1
 *
 * @author icewx
 * @since 2025-04-10
 */
@RestController
@RequestMapping("/eeg/eeg-data-block")
@AllArgsConstructor
@Api(tags = "获取eeg数据接口")
@CrossOrigin(origins = "*") // 允许所有域名跨域请求
public class EegDataBlockController {
    private final IEegDataBlockService eegDataBlockService;

    private final EegDataSaveService eegDataSaveService; //记录eeg数据

    private final EegDataReceivingService eegDataReceivingService;  //传输eeg数据



    /**
     * 获取时间集合
     * @return list集合
     */
    @GetMapping
    public List<String> timeList(){
        return eegDataBlockService.timeList();
    }

    /**
     * 获取所有点位信息(可以传某个时间段查询信息)
     * @param time 某个时间段(非必须)
     * @return EegDataBlockVO集合
     */
    @GetMapping("/list")
    public List<EegDataBlockVO> list(String time){
        return eegDataBlockService.eegList(time);
    }

    /**
     * 根据id查询数据信息
     * @param id
     * @return
     */
    @ApiOperation("根据id查询数据信息")
    @GetMapping("/{id}")
    public Result<List<EegDataBlock>> getById(@PathVariable Long id){
        return Result.success(eegDataBlockService.getInfoById(id));
    }


    @ApiOperation("开始传输EEG实时数据")
    @PostMapping("/start")
    public String startReceivingData() {
        eegDataReceivingService.startReceivingData();
        return "开始传输eeg实时数据 " ;

    }

    @ApiOperation("停止传输EEG实时数据")
    @PostMapping("/stop")
    public String stopReceivingData() {
        eegDataReceivingService.stopReceivingData();
        return "Data receiving stopped.";
    }

    /**
     * 开始接收数据
     * @param recordingId 记录ID
     * @return 操作结果
     */
    @ApiOperation("开始记录数据")
    @PostMapping("/save")
    public String startSaveData(@RequestParam Long recordingId) {
        eegDataSaveService.startSaveData(recordingId);
        return "Data receiving started with recordingId: " + recordingId;

    }

    /**
     * 停止接收数据
     * @return 操作结果
     */
    @ApiOperation("停止记录数据")
    @PostMapping("/stopSave")
    public String stopSaveData() {
        eegDataSaveService.stopSaveData();
        return "Data receiving stopped.";
    }
}
